$(function () {
    $.get(baseURL + 'renren-admin/sys/shoporder/getCounts/', function (r) {
        $("#orders").html(r.count);
    });
    $.get(baseURL + 'renren-admin/sys/shoporder/getMoneyTotal/', function (r) {
        $("#moneyOfMonth").html(r.moneyTotal);
    });
    $.get(baseURL + 'renren-admin/sys/merchant/getMerchantCounts/', function (r) {
        $("#merchantCounts").html(r.merchantCounts);
    });
    $.get(baseURL + 'renren-admin/sys/users/getUsersCounts/', function (r) {
        $("#usersCounts").html(r.usersCounts);
    });

    $.get(baseURL + 'renren-admin/sys/shoporder/orderList/', function (r) {

        vm.xArray = [];
        vm.payArray = [];
        vm.ordercountArray = [];
        for (var i = 0; i < r.list.length; i++) {
            vm.xArray.push(r.list[i].dayOfWeek);
            vm.payArray.push(parseInt(r.list[i].actualAmount));
            // vm.ordercountArray.push(parseInt(arrayData[i].actualAmount));
            // alert(vm.xArray)
            vm.chartImg();
        }
    });

    $("#jqGridUser").jqGrid({
        url: baseURL + 'renren-admin/sys/users/list',
        datatype: "json",
        colModel: [
            // { label: 'id', name: 'id', index: 'id', width: 50, key: true },
            { label: '日期', name: 'lastlogintime', index: 'lastlogintime', width: 80 },
            { label: '用户名', name: 'username', index: 'username', width: 80 },
            { label: '余额', name: 'balance', index: 'balance', width: 80 }
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: false,
        pager: "#jqGridPagerUser",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGridUser").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });

    $("#jqGridOrder").jqGrid({
        url: baseURL + 'renren-admin/sys/merchant/list',
        datatype: "json",
        colModel: [
            { label: '商户名称', name: 'name', index: 'name', width: 80 },
            { label: '详细地址', name: 'address', index: 'ADDRESS', width: 80 }
        ],
        viewrecords: true,
        height: 385,
        rowNum: 10,
        rowList : [10,30,50],
        rownumbers: true,
        rownumWidth: 25,
        autowidth:true,
        multiselect: false,
        pager: "#jqGridPagerOrder",
        jsonReader : {
            root: "page.list",
            page: "page.currPage",
            total: "page.totalPage",
            records: "page.totalCount"
        },
        prmNames : {
            page:"page",
            rows:"limit",
            order: "order"
        },
        gridComplete:function(){
            //隐藏grid底部滚动条
            $("#jqGridOrder").closest(".ui-jqgrid-bdiv").css({ "overflow-x" : "hidden" });
        }
    });
    vm.getLoadUserRole();
    vm.showAgent();
});

var vm = new Vue({
    el:'#rrapp',
    data:{
        showList: true,
        title: null,
        shopOrder: {},
        xArray:[],//租金额
        payArray:[],
        ordercountArray:[]  //订单
    },
    methods: {
        imgAll: function () {
            console.log("all")
            $.get(baseURL + 'renren-admin/sys/shoporder/orderList/', function (r) {

                vm.xArray = [];
                vm.payArray = [];
                vm.ordercountArray = [];
                for (var i = 0; i < r.list.length; i++) {
                    vm.xArray.push(r.list[i].dayOfWeek);
                    vm.payArray.push(parseInt(r.list[i].actualAmount));
                    vm.chartImg();
                }
            });
        },
        showAgent: function () {
            $("#agentid").show();
            var role = "";
            $.ajax({
                type: "POST",
                url: baseURL + "renren-admin/sys/role/getRoleLoginUser",
                async: false,
                success: function(r){
                    if(r.role!=null){
                        role = r.role.roleName;
                    }
                }
            });
            if(role!=""&&(role.indexOf("代理商") != -1||role.indexOf("业务员") != -1||role.indexOf("商户") != -1)){
                $("#agentid").hide();
            }
        },
        getLoadUserRole:function () {
            $("#btnlist").hide();
            var role = "";
            $.ajax({
                type: "POST",
                url: baseURL + "renren-admin/sys/role/getRoleLoginUser",
                async: false,
                success: function(r){
                    if(r.role!=null){
                        role = r.role.roleName;
                    }
                }
            });
            if(role==""||role.indexOf("管理员") != -1){
                $("#btnlist").show();
            }
        },
        chartImg:function(){
            var chart = Highcharts.chart('container', {
                chart: {
                    zoomType: 'xy'
                },
                title: {
                    text: '本周租金额'
                },
                xAxis: [{
                    categories: vm.xArray,
                    crosshair: true
                }],
                yAxis: [{
                    labels: {
                        format: '{value}',
                        style: {
                            color: Highcharts.getOptions().colors[1]
                        }
                    },
                    // title: {
                    //     text: '订单数量',
                    //     style: {
                    //         color: Highcharts.getOptions().colors[1]
                    //     }
                    // }
                },
                    {
                        title: {
                            text: '支付金额',
                            style: {
                                color: Highcharts.getOptions().colors[0]
                            }
                        },
                        labels: {
                            format: '{value} ',
                            style: {
                                color: Highcharts.getOptions().colors[0]
                            }
                        },
                        opposite: true
                    }
                ],
                tooltip: {
                    shared: true
                },
                legend: {
                    layout: '支付金额',
                    align: 'left',
                    x: 1200,
                    verticalAlign: 'top',
                    y: 1000,
                    floating: true,
                    backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
                },
                series: [{
                    name: '支付金额',
                    type: 'column',
                    yAxis: 1,
                    // type: 'spline',
                    data: vm.payArray
                }
                , {
                    name: '支付金额',
                    type: 'spline',
                    data: vm.payArray
                }
                ],
                credits: {
                    enabled: false     //不显示LOGO
                },
                exporting: {
                    enabled: false
                }
            });
        },
        imgXian: function () {
            console.log("折线图")
            $.get(baseURL + 'renren-admin/sys/shoporder/orderList/', function (r) {

                vm.xArray = [];
                vm.payArray = [];
                vm.ordercountArray = [];
                for (var i = 0; i < r.list.length; i++) {
                    vm.xArray.push(r.list[i].dayOfWeek);
                    vm.payArray.push(parseInt(r.list[i].actualAmount));
                    vm.chartXianImg();
                }
            });
        },
        chartXianImg:function(){
            var chart = Highcharts.chart('container', {
                chart: {
                    zoomType: 'xy'
                },
                title: {
                    text: '本周租金额'
                },
                xAxis: [{
                    categories: vm.xArray,
                    crosshair: true
                }],
                yAxis: [{
                    labels: {
                        format: '{value}',
                        style: {
                            color: Highcharts.getOptions().colors[1]
                        }
                    },
                },
                    {
                        title: {
                            text: '支付金额',
                            style: {
                                color: Highcharts.getOptions().colors[0]
                            }
                        },
                        labels: {
                            format: '{value} ',
                            style: {
                                color: Highcharts.getOptions().colors[0]
                            }
                        },
                        opposite: true
                    }
                ],
                tooltip: {
                    shared: true
                },
                series: [{
                    name: '支付金额',
                    type: 'column',
                    yAxis: 1,
                    type: 'spline',
                    data: vm.payArray
                }
                ],
                credits: {
                    enabled: false     //不显示LOGO
                },
                exporting: {
                    enabled: false
                }
            });
        },
        imgZhu: function () {
            console.log("柱状图")
            $.get(baseURL + 'renren-admin/sys/shoporder/orderList/', function (r) {

                vm.xArray = [];
                vm.payArray = [];
                vm.ordercountArray = [];
                for (var i = 0; i < r.list.length; i++) {
                    vm.xArray.push(r.list[i].dayOfWeek);
                    vm.payArray.push(parseInt(r.list[i].actualAmount));
                    vm.chartZhuImg();
                }
            });
        },
        chartZhuImg:function(){
            var chart = Highcharts.chart('container', {
                chart: {
                    zoomType: 'xy'
                },
                title: {
                    text: '本周租金额'
                },
                xAxis: [{
                    categories: vm.xArray,
                    crosshair: true
                }],
                yAxis: [{
                    labels: {
                        format: '{value}',
                        style: {
                            color: Highcharts.getOptions().colors[1]
                        }
                    },
                    // title: {
                    //     text: '订单数量',
                    //     style: {
                    //         color: Highcharts.getOptions().colors[1]
                    //     }
                    // }
                },
                    {
                        title: {
                            text: '支付金额',
                            style: {
                                color: Highcharts.getOptions().colors[0]
                            }
                        },
                        labels: {
                            format: '{value} ',
                            style: {
                                color: Highcharts.getOptions().colors[0]
                            }
                        },
                        opposite: true
                    }
                ],
                tooltip: {
                    shared: true
                },
                legend: {
                    layout: '订单数量',
                    align: 'left',
                    x: 120,
                    verticalAlign: 'top',
                    y: 100,
                    floating: true,
                    backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || '#FFFFFF'
                },
                series: [{
                    name: '支付金额',
                    type: 'column',
                    yAxis: 1,
                    // type: 'spline',
                    data: vm.payArray
                }
                ],
                credits: {
                    enabled: false     //不显示LOGO
                },
                exporting: {
                    enabled: false
                }
            });
        }
    }
});